<template>
    <div class="qingwu">
        <div class="admin_table_page_title">楼层管理</div>
        <div class="unline underm"></div>

        <estate-search :searchConfig="searchConfig" @searchParams="search"></estate-search>

        <div class="admin_table_handle_btn">
            <a-button @click="$router.push('/Estate/element/form')" type="primary" icon="plus">添加楼层</a-button>
            <a-button class="admin_delete_btn" type="danger" icon="delete" @click="del">批量删除</a-button>
        </div>
        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false" :loading="table_loading" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="f_id" tableLayout="auto">
                <span slot="house_name" slot-scope="rows">
                    {{ rows.house.house_num }} 号楼
                </span>
                <span slot="element_name" slot-scope="rows">
                    {{ rows.element.element_num }} 单元
                </span>
                <span slot="floor_name" slot-scope="rows">
                    {{ rows.floor }} 层
                </span>
                <span slot="action" slot-scope="rows">
                    <a-button icon="edit" @click="$router.push('/Estate/element/form/'+rows.f_id)">编辑</a-button>
                </span>
            </a-table>
            <div class="admin_pagination" v-if="total>0">
                <a-pagination v-model="params.page" :page-size.sync="params.per_page" :total="total" @change="onChange" show-less-items />
            </div>
        </div>
    </div>
</template>

<script>
import estateSearch from '@/components/estate/search'

export default {
    components: {estateSearch,},
    props: {},
    data() {
        return {
            params: {
                page: 1,
                per_page: 30,
            },
            total: 0, //总页数
            searchConfig: [
                {label: '所属小区', name: 'c_id', type: 'select', data: [{label: '全部', value: ''}]},
                {label: '楼号', name: 'house_num', type: 'text'},
                {label: '单元号', name: 'element_num', type: 'text'},
                {label: '楼层',name: 'floor',type:'text'},
                //   {label:'上架状态',name:'goods_status',type:'select',data:[{label:'全部',value:''},{label:'上架',value:1},{label:'下架',value:0}]},
                //   {label:'审核状态',name:'goods_verify',type:'select',data:[{label:'已审核',value:1},{label:'未审核',value:0}]},
                //   {label:'商品品牌',name:'brand_id',type:'text'},
                //   {label:'商品分类',name:'class_id',type:'text'},
            ],
            selectedRowKeys: [], // 被选择的行
            columns: [
                {title: '小区', dataIndex: 'community.community_name'},
                {title: '楼栋', scopedSlots: {customRender: 'house_name'}},
                {title: '单元', scopedSlots: {customRender: 'element_name'}},
                {title: '楼层', scopedSlots: {customRender: 'floor_name'}},
                {title: '操作', scopedSlots: {customRender: 'action'}},
            ],
            list: [],
            count: [],
            table_loading: true,
        };
    },
    watch: {},
    computed: {},
    methods: {
        search(params) {
            let page = this.params.page;
            let per_page = this.params.per_page;
            this.params = params;
            this.params.page = page;
            this.params.per_page = per_page;
            this.onload();
        },
        // 选择分页
        onChange(e){
            this.params.page = e;
            this.onload();
        },
        // 选择框被点击
        onSelectChange(selectedRowKeys) {
            this.selectedRowKeys = selectedRowKeys;
        },
        // 删除
        del() {
            if (this.selectedRowKeys.length == 0) {
                return this.$message.error('未选择数据.');
            }
            this.$confirm({
                title: '你确定要删除选择的数据？',
                content: '确定删除后无法恢复.',
                okText: '是',
                okType: 'danger',
                cancelText: '取消',
                onOk: () => {
                    let ids = this.selectedRowKeys.join(',');
                    this.$delete(this.$api.estateElement + '/' + ids).then(res => {
                        if (res.code == 200) {
                            this.onload();
                            this.$message.success('删除成功');
                        } else {
                            this.$message.error(res.msg)
                        }
                    });

                },
            });
        },
        get_group() {
            this.$get(this.$api.estateCommunity).then(res => {
                let list = [];
                console.log(res.data);
                res.data.data.forEach(item => {
                    list.push({label: item.community_name, value: item.community_id})
                })
                this.searchConfig.forEach(item => {
                    if (item.name == 'c_id') {
                        item.data = item.data.concat(list)
                    }
                })
            });
        },
        onload() {
            this.table_loading = true;
            this.$get(this.$api.estateElement, this.params).then(res => {
                this.list = res.data.data;
                this.count = res.data.count;
                this.total = res.data.total;
                this.table_loading = false;
            });
        },
        to_nav(e) {
            this.params.goods_verify = e;
            this.params.page = 1;
            this.onload();
        },
    },
    created() {
        this.onload();
        this.get_group();
    },
    mounted() {
    }
};
</script>
<style lang="scss" scoped>

</style>
